package normal.哈希表;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhuYi
 * @create 2025/1/16 22:52
 */
public class HashTest {
    public static void main(String[] args) {
        //初始化哈希表
        HashMap<Integer, String> hashMap = new HashMap<>();
        hashMap.put(1, "小朱");
        hashMap.put(2, "小爽");
        hashMap.put(3, "小斌");
        hashMap.put(4, "小阳");
        hashMap.put(5, "小于");
        //查询
        String s = hashMap.get(2);
        System.out.println(s);
        //删除
        hashMap.remove(4);
        //获取长度
        int size = hashMap.size();
        System.out.println(size);

        /* 遍历哈希表 */
        for (Map.Entry<Integer, String> kv : hashMap.entrySet()) {
            System.out.println(kv.getKey() + " = " + kv.getValue());
        }

        //单独遍历键
        for (int i : hashMap.keySet()) {
            System.out.println(i);
        }

        //单独遍历值
        for (String str : hashMap.values()) {
            System.out.println(str);
        }
    }
}
